<?php

use app\models\Mall;
use app\widgets\MallMBottomToolbarWidget;
use yii\helpers\Url;

$web = Url::base();
$integral_rate = Mall::getCurrentInstitutionIntegralRate();
$institution_code = Mall::getCurrentInstitutionCode();
$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$userIntegral = \app\models\User::getUserIntegral(Mall::getCurrentUserId());
$this->title = $site_name;


///场景
$scene_count=4;
$scene = [];
$extendCategoryList_tmp = [];
$scene_i=1;
$scene=array_pad($scene,$scene_count+1,['type'=>'','id'=>'','name'=>'','image_url'=>'']);

foreach ($extendCategoryList as $item) {
    $identifier_code = $item['identifier_code'];
    $is_find=false;
    for($i=1;$i<=$scene_count;$i++){
        if ($identifier_code == 'a-' . $i) {
            $scene[$i] = $item;
            $is_find=true;
            break;
        }
    }
    if($is_find==false){
        $extendCategoryList_tmp[] = $item;
    }

}
//var_dump($scene);exit;
//var_dump($extendCategoryList_tmp);exit;
$extendCategoryList = $extendCategoryList_tmp;
?>


<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/index.css"/>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/cross-title.css"/>
<style type="text/css">
    .bargain-frame .bargain-content-frame .goods-item div {
        background-image: url('<?= $web ?>/images/mall-m/index-icon-bargain.png');
    }

    .back-top {
        background-image: url('<?= $web ?>/images/mall-m/index-icon-top.png');
    }

    .popup .heade-commodity {
        -webkit-mask: url(<?= $web ?>/images/mall-m/window-mask.png);
        -webkit-mask-size: cover;
    }

    .window-btn {
        background: url(<?= $web ?>/images/mall-m/window-btn.png) no-repeat;
        background-size: 100% 100%;
        z-index: 888;
    }

    .popup {
        background: url(<?= $web ?>/images/mall-m/popup-bg-2.png) no-repeat;
        background-size: cover;
    }

    .popup .big-commodity {
        -webkit-mask: url(<?= $web ?>/images/mall-m/popup-mak-2.png);
        -webkit-mask-size: cover;
    }

    .popup .popup-more-btn {
        background: url(<?= $web ?>/images/mall-m/popup-more-btn.png) no-repeat;
        background-size: cover;
    }

    .popup .popup-more-btn:active {
        background-position: 0 -2rem;
    }
</style>

<div class="main">
    <div class="header">
        <a class="search" href="<?= Url::to(['mall-m/search', 'institution_code' => $institution_code]) ?>">
            <img src="<?= $web ?>/images/mall-m/index-icon-search.png">
            <label>大闸蟹</label>
        </a>
        <?php
             if (Mall::getCurrentUser() == null) {
          ?>
            <a href="<?=Url::to(['mall-m/login']) ?>" class="login-link">
                <img src="<?= $web ?>/images/mall-m/index-icon-integra2.png">
                <p>登录</p>
            </a>
        <?php
             }else {
        ?>
                 <div class="integral-frame">
                     <img class="icon" src="<?= $web ?>/images/mall-m/index-icon-integral.png">
                     <div class="value-frame">
                         <div class="title"><?= $integral_unit ?>余额</div>
                         <div class="value">
                             <?= floor($integral) ?>
                         </div>
                     </div>
                 </div>
        <?php
             }
        ?>
    </div>
    <div class="banner">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <?php
                foreach ($wap_fbanner as $item) {
                    $href='';
                    if($item['link_url']){
                        $link_url=$item['link_url'];
                        $href=" href='$link_url' ";
                    }
                    ?>
                    <div class="swiper-slide">
                        <a  <?=$href?> > <img src="<?= $item['image_url'] ?>"></a>
                    </div>
                    <?php
                }
                ?>
                <!-- <div class="swiper-slide">
                   <a href="http://www.baidu.com"> <img src="<? /*= $web */ ?>/images/mall-m/index-banner.jpg"></a>
                </div>-->
            </div>
            <!-- 如果需要分页器 -->
            <div class="swiper-pagination"></div>
        </div>
        <script>
            $(function () {
                var swiperBanner = new Swiper('.banner .swiper-container', {
                    direction: 'horizontal',
                    autoplay: 3000,
                    autoplayDisableOnInteraction: false,
                    speed: 800,
                    loop: true,

                    // 如果需要分页器
                    pagination: '.swiper-pagination'
                })
            });
        </script>
    </div>
    <a class="vip" href="virtual-coupon-list?institution_code=<?= $institution_code ?>" style="display: block;">
        <img src="<?= $web ?>/images/mall-m/index-vip.jpg">
    </a>
    <div class="scene-frame">
        <div class="scene-block">
            <?php $scene_tmp=$scene[4];?>
            <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                <img class="scene-1"  src="<?= $scene_tmp['image_url'] ?>">
            </a>
            <div class="block-right">
                <?php $scene_tmp=$scene[1];?>
                <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                    <img class="scene-2" src="<?= $scene_tmp['image_url'] ?>">
                </a>
                <?php $scene_tmp=$scene[2];?>
                <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                    <img class="scene-3" src="<?= $scene_tmp['image_url'] ?>">
                </a>
                <?php $scene_tmp=$scene[3];?>
                <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                    <img class="scene-4" src="<?= $scene_tmp['image_url'] ?>">
                </a>
            </div>
        </div>
        <div class="scene-list">
            <?php
            foreach ($extendCategoryList as $item) {
                $link_url = $item['link_url'];
//                type为2 link_url要换成产品扩展分类列表链接
                if ($item['type'] == '2') {
                    $link_url = Url::to(['mall-m/goods-list','cv'=>1, 'goodsExtendCategoryCode' => $item['id'], 'goodsListTitle' => '' . $item['name'], 'institution_code' => $institution_code]);
                }
                ?>
                <a class="scene-item" href="<?= $link_url ?>">
                    <img src="<?= $item['image_url'] ?>">
                </a>
                <?php
            }
            ?>
            <!--  <a class="scene-item" href="http://www.baidu.com">
                <img src="<? /*= $web */ ?>/images/mall-m/index-scene-item.jpg">
            </a>-->
        </div>
    </div>

   <!-- <a class="game" href="game-list?institution_code=<?/*= $institution_code */?>">
        <img src="<?/*= $web */?>/images/mall-m/index-game.jpg">
    </a>-->

    <?php
    //如果没有特价产品，隐藏
    if (count($activityBargainList) > 0) {
        ?>
        <!--特价专区-->
        <div class="bargain-frame">
            <a class="bargain-title" href="<?=Url::to(['mall-m/goods-list','isActivity'=>1,'goodsListTitle'=>'特价专区','t'=>time(), 'institution_code' => $institution_code]) ?>">
                <img src="<?= $web ?>/images/mall-m/index-bargain-title.jpg">
            </a>
            <div class="bargain-content-frame">
                <div class="swiper-container">
                    <div class="swiper-wrapper">
                        <?php
                        foreach ($bargainGoodsList as $item) {
                            ?>
                            <div class="swiper-slide">
                                <a class="goods-item" href="<?=Url::to(['mall-m/goods-detail','goods_code'=> $item['goods_code'],  'institution_code' => $institution_code]) ?>">
                                    <img src="<?= $item['image_url'] ?>@140w">
                                    <div></div>
                                </a>
                            </div>
                            <?php
                        }
                        ?>
                        <!--                     <div class="swiper-slide">
                                                 <a class="goods-item">
                                                     <img src="images/mall-m/11.jpg">
                                                     <div></div>
                                                 </a>
                                             </div>-->
                    </div>
                </div>
                <script>
                    var swiperBargain = new Swiper('.bargain-content-frame .swiper-container', {
                        slidesPerView: 3,
                        spaceBetween: 35,
                        freeMode: true,
                        freeModeSticky: true,
                        autoplayDisableOnInteraction: false,
                        loop: true,
                        speed: 1000,
                        autoplay: 1000
                    });
                </script>
            </div>
        </div>
        <?php
    }
    ?>

    <div class="hot-frame">
<!--        <a class="hot-title">-->
<!--            <img src="--><?//= $web ?><!--/images/mall-m/index-hot-title.jpg">-->
<!--        </a>-->
        <div class="hot-title">热销精选</div>
        <div class="goods-grid-frame">
            <?php
            foreach ($hotGoodsList as $item) {
                ?>

                <a class="goods-item" href=" <?=Url::to(['mall-m/goods-detail','goods_code'=> $item['code'],  'institution_code' => $institution_code]) ?>">
                    <img src="<?= $item['image_url'] ?>@300w">
                    <label class="name crossborder">
                        <?php
                        if($item['is_crossborder']=='1'){
                            ?>
                            <span>跨境</span>
                            <?php
                        }
                        ?>
                        <?= $item['name'] ?></label>
                    <label class="price"><?= $item['integral_unit'] ?>：<?= intval($item['selling_integral']) ?></label>
                </a>
                <?php
            }
            ?>
            <!-- <a class="goods-item" href="http://www.baidu.com">
                <img src="<? /*= $web */ ?>/images/mall-m/1.jpg">
                <label class="name">呆萌抱抱大肚圣诞陶瓷杯大肚圣圣诞老人</label>
                <label class="price">积分：1198</label>
            </a>-->

        </div>
    </div>
    <?=MallMBottomToolbarWidget::widget(['actionName'=>'index'])?>
    <div class="back-top"></div>

    <?php
    if ($card != null) {
        ?>
        <div style="display: block;">
            <script type="application/javascript">
                $(function () {
                    $(".window-btn").animate({"right": "-.5rem"}, 300);
                    $("body,html").css({height: "100%", overflow: "hidden"});
                });
            </script>
            <div class="window-btn">
                <p>礼卡兑换</p>
            </div>

            <div class="popup">
                <div class="heade">
                    <img class="head-img" src="<?= $web ?>/images/mall-m/popup-head-img.png"/>
                    <div class="close-btn">
                        <img class="close-btn-img" src="<?= $web ?>/images/mall-m/popup-close-btn.png"/>
                    </div>
                </div>
                <div class="popup-title-img f-l">
                    <img src="<?= $web ?>/images/mall-m/popup-title-2.png"/>
                </div>

                <?php
                if (count($card['goods_list']) > 0) {
                    ?>
                    <a href="goods-detail?goods_code=<?= $card['goods_list'][0]['code'] ?>&institution_code=<?= $institution_code ?>">
                        <div class="big-commodity f-r">
                            <img src="<?= $card['goods_list'][0]['image'] ?>@250w"/>
                            <p class="title"><?= $card['goods_list'][0]['name'] ?></p>
                        </div>
                    </a>
                    <?php
                }
                ?>

                <div class="center-commodity">
                    <?php
                    for ($i = 1; $i < count($card['goods_list']); $i++) {
                        if ($i > 6) {
                            break;
                        }
                        ?>
                        <a href="goods-detail?goods_code=<?= $card['goods_list'][$i]['code'] ?>&institution_code=<?= $institution_code ?>">
                            <div class="f-l content">
                                <img src="<?= $card['goods_list'][$i]['image'] ?>@166w"/>
                                <p class="title"><?= $card['goods_list'][$i]['name'] ?></p>
                            </div>
                        </a>
                        <?php
                    }
                    ?>
                </div>
                <a href="<?= Url::to(['mall-m/goods-list', 'integralFrom' => 0, 'integralTo' => intval($userIntegral), 'sort' => 2, 'institution_code' => $institution_code]) ?>" class="popup-more-btn"></a>
            </div>

            <div class="shade"></div>
        </div>
        <?php
    }
    ?>
</div>

<script type="application/javascript">
    $(function () {
        $(document).scroll(function () {
            var scrollTop = $(document).scrollTop();
            if (scrollTop > 500) {
                $('.back-top').show(500);
            } else {
                $('.back-top').hide(500);
            }
        });

        $('.back-top').click(function () {
            $('body,html').animate({scrollTop: 0}, 200);
        });


        $(".window-btn").click(function () {
            $(".popup").show(300);
            $(".shade").animate({"opacity": "show"}, 300);
            $(".window-btn").animate({"right": "-.5rem"}, 300);
            $(".window-btn p").animate({"opacity": "hide"}, 300);
            $("body,html").css({height: "100%", overflow: "hidden"});
        });
        $(".close-btn,.shade").click(function () {
            $(".popup").hide(300);
            $(".shade").animate({"opacity": "hide"}, 300);
            $(".window-btn").animate({"right": "0"}, 300);
            $(".window-btn p").animate({"opacity": "show"}, 300);
            $("body,html").css({overflow: "auto", height: "auto"});
        });
    });
</script>